package com.zonda.sampleretrofit2.view;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.CallSuper;
import android.util.AttributeSet;
import android.widget.FrameLayout;

public abstract class NewsListItemBaseLayout extends FrameLayout implements IBaseReleaser {

  private boolean isFinishInflate = false;

  private Paint mDividerLinePaint;

  public NewsListItemBaseLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mDividerLinePaint = new Paint();
    mDividerLinePaint.setColor(Color.GRAY);
  }

  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();
    onInitChildView();
    isFinishInflate = true;
  }

  @CallSuper
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (!isFinishInflate) {
      throw new IllegalArgumentException("This Layout must inflate from xml");
    }
  }

  @Override
  protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    canvas.save();
    canvas.clipRect(0, getHeight() - 1, getWidth(), getHeight());
    canvas.drawLine(0, getHeight() - 1, getWidth(),
        getHeight() - 1, mDividerLinePaint);
    canvas.restore();
  }

  @CallSuper
  @Override
  public void freeMemory() {

  }

  @CallSuper
  @Override
  public void destroy() {

  }

  abstract void onInitChildView();
}
